/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Copyright (C) 2011-2020 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
2020-04-02 Jeff Heylmun:    Modified class for a density based thermodynamic
                            class
-------------------------------------------------------------------------------
License
    This file is derivative work of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
    Foam::blendedBlastThermo

Description
    Templated class to allow for blending of multiple equation of state.

SourceFiles
    blendedBlastThermo.C

\*---------------------------------------------------------------------------*/

#ifndef blendedBlastThermo_H
#define blendedBlastThermo_H

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#include "blastThermo.H"

namespace Foam
{

/*---------------------------------------------------------------------------*\
                           Class blendedBlastThermo Declaration
\*---------------------------------------------------------------------------*/

template<class BasicThermo, class Thermo1, class Thermo2>
class blendedBlastThermo
:
    public BasicThermo,
    public Thermo1,
    public Thermo2
{
protected:

    typedef BasicThermo baseThermo;
    typedef Thermo1 thermoType1;
    typedef Thermo2 thermoType2;

    //- Residual value of activation parameter
    scalar residualActivation_;


    // Protected functions

        //- Return a volScalarField of the given property
        template<class Method, class ... Args>
        tmp<volScalarField> volScalarFieldProperty
        (
            const word& psiName,
            const dimensionSet& psiDim,
            Method psiMethod,
            const Args& ... args
        ) const;

        //- Return a scalarField of the given property on a patch
        template<class Method, class ... Args>
        tmp<scalarField> patchFieldProperty
        (
            Method psiMethod,
            const label patchi,
            const Args& ... args
        ) const;

        //- Return a scalarField of the given property on a cell set
        template<class Method, class ... Args>
        tmp<scalarField> cellSetProperty
        (
            Method psiMethod,
            const labelList& cells,
            const Args& ... args
        ) const;

        //- Return a volScalarField of the given property
        template<class Method1, class Method2, class ... Args>
        tmp<volScalarField> blendedVolScalarFieldProperty
        (
            const word& psiName,
            const dimensionSet& psiDim,
            Method1 psiMethod1,
            Method2 psiMethod2,
            const Args& ... args
        ) const;

        //- Return a scalarField of the given property on a patch
        template<class Method1, class Method2, class ... Args>
        tmp<scalarField> blendedPatchFieldProperty
        (
            Method1 psiMethod1,
            Method2 psiMethod2,
            const label patchi,
            const Args& ... args
        ) const;

        //- Return a scalarField of the given property on a cell set
        template<class Method1, class Method2, class ... Args>
        tmp<scalarField> blendedCellSetProperty
        (
            Method1 psiMethod1,
            Method2 psiMethod2,
            const labelList& cells,
            const Args& ... args
        ) const;

        //- Return a scalar of the given property on a cell
        template<class Method1, class Method2, class ... Args>
        scalar blendedCellProperty
        (
            Method1 psiMethod1,
            Method2 psiMethod2,
            const label celli,
            const Args& ... args
        ) const;

        //- Return a scalar of the given property on a cell
        template<class Method1, class Method2, class ... Args>
        scalar blendedPatchFaceProperty
        (
            Method1 psiMethod1,
            Method2 psiMethod2,
            const label patchi,
            const label facei,
            const Args& ... args
        ) const;

        //- Return the blending field for patchi
        virtual tmp<scalarField> x(const label) const = 0;

        //- Return the blending field for celli
        virtual scalar cellx(const label) const = 0;

        //- Return the blending field for patchi facei
        virtual scalar patchFacex(const label, const label) const = 0;


public:

    // Constructor

        //- Construct with input field
        blendedBlastThermo
        (
            const fvMesh& mesh,
            const dictionary& dict,
            const dictionary& dict1,
            const dictionary& dict2,
            const word& phaseName,
            const word& masterName = word::null
        );


    //- Destructor
    virtual ~blendedBlastThermo();



    // Member functions

        //- Return the thermo name
        virtual word thermoName() const;

        //- Thermodynamic and transport functions

            using BasicThermo::he;
            //- Enthalpy/Internal energy
            //  for given pressure and temperature [J/kg]
            virtual tmp<volScalarField> he
            (
                const volScalarField& p,
                const volScalarField& T
            ) const;

            //- Enthalpy/Internal energy for cell-set [J/kg]
            virtual tmp<scalarField> he
            (
                const scalarField& T,
                const labelList& cells
            ) const;

            //- Enthalpy/Internal energy for patch [J/kg]
            virtual tmp<scalarField> he
            (
                const scalarField& T,
                const label patchi
            ) const;

            //- Enthalpy/Internal energy for a cell [J/kg]
            virtual scalar cellHE
            (
                const scalar T,
                const label celli
            ) const;

            //- Enthalpy/Internal energy for patch and face [J/kg]
            virtual scalar patchFaceHE
            (
                const scalar T,
                const label patchi,
                const label facei
            ) const;

            //- Sensible enthalpy [J/kg/K]
            virtual tmp<volScalarField> hs() const;

            //- Sensible enthalpy
            //  for given pressure and temperature [J/kg]
            virtual tmp<volScalarField> hs
            (
                const volScalarField& p,
                const volScalarField& T
            ) const;

            //- Sensible enthalpy for patch [J/kg/K]
            virtual tmp<scalarField> hs
            (
                const scalarField& T,
                const label patchi
            ) const;

            //- Sensible enthalpy for cell-set [J/kg]
            virtual tmp<scalarField> hs
            (
                const scalarField& T,
                const labelList& cells
            ) const;

            //- Absolute enthalpy [J/kg/K]
            virtual tmp<volScalarField> ha() const;

            //- Absolute enthalpy
            //  for given pressure and temperature [J/kg]
            virtual tmp<volScalarField> ha
            (
                const volScalarField& p,
                const volScalarField& T
            ) const;

            //- Absolute enthalpy for patch [J/kg/K]
            virtual tmp<scalarField> ha
            (
                const scalarField& T,
                const label patchi
            ) const;

            //- Absolute enthalpy for cell-set [J/kg]
            virtual tmp<scalarField> ha
            (
                const scalarField& T,
                const labelList& cells
            ) const;

            //- Enthalpy of formation [J/kg]
            virtual tmp<volScalarField> hc() const;

            //- Flame temperature [K]
            virtual tmp<volScalarField> flameT() const;

            //- Temperature from enthalpy/internal energy
            virtual tmp<volScalarField> THE() const;

            //- Temperature from enthalpy/internal energy
            virtual tmp<volScalarField> THE
            (
                const volScalarField& h,
                const volScalarField& p,
                const volScalarField& T0    // starting temperature
            ) const;

            //- Temperature from enthalpy/internal energy for cell-set
            virtual tmp<scalarField> THE
            (
                const scalarField& he,
                const scalarField& T0,      // starting temperature
                const labelList& cells
            ) const;

            //- Temperature from enthalpy/internal energy for patch
            virtual tmp<scalarField> THE
            (
                const scalarField& he,
                const scalarField& T0,      // starting temperature
                const label patchi
            ) const;

            //- Temperature from enthalpy/internal energy for celli
            virtual scalar cellTHE
            (
                const scalar he,
                const scalar T0,
                const label celli
            ) const;

            using BasicThermo::Cp;

            //- Heat capacity at constant pressure for patch [J/kg/K]
            virtual tmp<scalarField> Cp
            (
                const scalarField& T,
                const label patchi
            ) const;

            //- Heat capacity at constant pressure for a cell [J/kg/K]
            virtual scalar cellCp(const scalar, const label) const;

            using BasicThermo::Cv;

            //- Heat capacity at constant volume for patch [J/kg/K]
            virtual tmp<scalarField> Cv
            (
                const scalarField& T,
                const label patchi
            ) const;

            //- Heat capacity at constant volume for a cell [J/kg/K]
            virtual scalar cellCv(const scalar, const label) const;

            using BasicThermo::Cpv;

            //- Heat capacity at constant pressure/volume for patch [J/kg/K]
            virtual tmp<scalarField> Cpv
            (
                const scalarField& T,
                const label patchi
            ) const;

            //- Heat capacity at constant pressure/volume for a cell [J/kg/K]
            virtual scalar cellCpv(const scalar, const label) const;

            //- Heat capacity at constant pressure/volume for a patch and face [J/kg/K]
            virtual scalar patchFaceCpv
            (
                const scalar,
                const label,
                const label
            ) const;

             //- Molecular weight [kg/kmol]
            virtual tmp<volScalarField> W() const;

            //- Molecular weight for patch [kg/kmol]
            virtual tmp<scalarField> W(const label patchi) const;

            //- Molecular weight for cell [kg/kmol]
            virtual scalar cellW(const label celli) const;
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#ifdef NoRepository
    #include "blendedBlastThermo.C"
#endif

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //
